package com.jxb.broker.store;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class MmapTest {
    public static void main(String[] args) throws IOException {
        RandomAccessFile file = new RandomAccessFile("C:\\Users\\86177\\Documents\\learn\\rocketmq\\store\\commitlog\\commit.log", "rw");
        FileChannel fileChannel = file.getChannel();
        long fileSize = fileChannel.size();
        MappedByteBuffer map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, fileSize);
        byte[] newData = "Hello, jiaoxioabo!".getBytes();
        if (newData.length <= map.remaining()) {
            map.position(0);
            map.put(newData);
        }
        fileChannel.force(false);

    }
}
